const user = {
  namespaced: true,
  state: {
    token: window.localStorage.getItem('token'),
    refreshToken: window.localStorage.getItem('refreshToken'),
    cancelTokenArr: [] // 取消请求token数组
  },
  getters: {},
  mutations: {
    // 登录之后设置token
    setToken (state, token) {
    // 存储到vuex中
      state.token = token
      // 存储到localStorage中
      window.localStorage.setItem('token', token)
    },
    pushToken (state, src) {
      state.cancelTokenArr.push(src.cancelToken)
    },
    clearToken (state) {
      state.cancelTokenArr.forEach(item => {
        item('路由跳转取消请求')
      })
      state.cancelTokenArr = []
    },
    setRefreshToken (state, refreshToken) {
      // 1. 修改vuex的数据
      state.refreshToken = refreshToken
      // 2. 同步修改本地
      window.localStorage.setItem('refreshToken', refreshToken)
    }
  }

}

export default user
